/*
 * Student.cpp
 *
 * Version: $Id: Student.cpp 64 2011-11-26 08:00:31Z s8376@pjwstk.edu.pl $
 */
#include <iostream>
#include <string.h>
#include "Student.h"

using namespace std;

Student::Student(char* forename, char* surname, char* pesel, char* index, int age, int semester, bool sex) :
    m_forename(strdup(forename)), m_surname(strdup(surname)),
            m_pesel(strdup(pesel)), m_index(strdup(index)), m_age(age),
            m_semester(semester), m_sex(sex)
{
}
Student::Student(Student& ob) :
    m_forename(strdup(ob.m_forename)), m_surname(strdup(ob.m_surname)),
            m_pesel(strdup(ob.m_pesel)), m_index(strdup(ob.m_index)),
            m_age(ob.m_age), m_semester(ob.m_semester), m_sex(ob.m_sex)
{
}
Student::~Student()
{
    delete[] m_forename;
    m_forename = 0;
    delete[] m_surname;
    m_surname = 0;
    delete[] m_pesel;
    m_pesel = 0;
    delete[] m_index;
    m_index = 0;
}
bool Student::checkChars(char* a, char* b)
{
    while (*a != 0) {
        if (*a != *b) {
            return false;
        }
        a++;
        b++;
    }
    return true;
}
void Student::show()
{
    cout << "Params\t:" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "Surname\t\t:\t" << m_surname << endl;
    cout << "Forename\t:\t" << m_forename << endl;
    cout << "PESEL\t\t:\t" << m_pesel << endl;
    cout << "Index\t\t:\t" << m_index << endl;
    cout << "Age\t\t:\t" << m_age << endl;
    cout << "Semester\t:\t" << m_semester << endl;
    cout << "Sex\t\t:\t" << (m_sex ? "Kobieta" : "Meżczyzna") << endl;
    cout << endl;
}
void Student::showDifferences(const Student& ob)
{
    cout << "Differences\t:\tLeft (this) object\tRight (parameter) object"
            << endl;
    cout
            << "---------------------------------------------------------------------------------"
            << endl;

    if (checkChars(m_surname, ob.m_surname) == false) {
        cout << "Surname\t\t:\t" << m_surname << "\t\t\t" << ob.m_surname
                << endl;
    }
    if (checkChars(m_forename, ob.m_forename) == false) {
        cout << "Forename\t:\t" << m_forename << "\t\t\t" << ob.m_forename
                << endl;
    }
    if (checkChars(m_pesel, ob.m_pesel) == false) {
        cout << "PESEL\t\t:\t" << m_pesel << "\t\t" << ob.m_pesel << endl;
    }
    if (checkChars(m_index, ob.m_index) == false) {
        cout << "Index\t\t:\t" << m_index << "\t\t\t" << ob.m_index << endl;
    }
    if (m_age != ob.m_age) {
        cout << "Age\t\t:\t" << m_age << "\t\t\t" << ob.m_age << endl;
    }
    if (m_semester != ob.m_semester) {
        cout << "Semester\t:\t" << m_semester << "\t\t\t" << ob.m_semester
                << endl;
    }
    if (m_sex != ob.m_sex) {
        cout << "Sex\t\t:\t" << (m_sex ? "Kobieta" : "Meżczyzna") << "\t\t\t"
                << (ob.m_sex ? "Kobieta" : "Meżczyzna") << endl;
    }

    cout
            << "---------------------------------------------------------------------------------"
            << endl;
    cout << endl;
}
